home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
bison
/
RpcalcErrp
< prev
next >
Wrap
Text File
|
1995-06-28
|
1KB
|
31 lines
Rpcalc Error
Previous: <Rpcalc Main=>RpcalcMaio> * Next: <Rpcalc Gen=>RpcalcGeo> * Up: <RPN Calc=>RPNCalc>
#Wrap on
{fH4}The Error Reporting Routine{f}
When {fCode}yyparse{f} detects a syntax error, it calls the error reporting
function {fCode}yyerror{f} to print an error message (usually but not always
{fCode}"parse error"{f}). It is up to the programmer to supply {fCode}yyerror{f}
(\*Note <Interface=>Interface>: Parser C-Language Interface), so here is the definition we will use:
#Wrap off
#fCode
\#include <stdio.h>
yyerror (s) \/\* Called by yyparse on error \*\/
char \*s;
\{
printf ("%s\\n", s);
\}
#f
#Wrap on
After {fCode}yyerror{f} returns, the Bison parser may recover from the error
and continue parsing if the grammar contains a suitable error rule
(\*Note <Error Recovery=>ErrorRecov>). Otherwise, {fCode}yyparse{f} returns nonzero. We
have not written any error rules in this example, so any invalid input will
cause the calculator program to exit. This is not clean behavior for a
real calculator, but it is adequate in the first example.